#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Time  : 2021/3/21 13:45
# @File  : test.py


"""
<span class="title">肖申克的救赎</span>
"""

import re
from urllib.request import urlopen, Request

top_urls = []
top_num = 1
url = "https://movie.douban.com/top250?start="
for num in range(4):
    top_urls.append(url + str(num * 25))
print('----------电影top100----------')
for i in top_urls:
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'}
    ret = Request(i, headers=headers)
    res = urlopen(ret)
    html = res.read().decode('utf-8')
    top_tag = re.compile(r'<span class="title">(.*)</span>')
    title = re.findall(top_tag, html)
    for i in title:
        if i.find('/') == -1:
            print('Top' +str(top_num) + '  ' + i)
            top_num += 1